%%
%First the example plots over space - Figure 5D.
load('slope_distance_info.mat')

%Now plot the above
count = 1; 
nGroups = 6;

for k = 1:length(slopes_noise) %Loop through selected days

    %Grab distance measures
    dists = distances_noise{k}; slps = slopes_noise{k};
    %Now sort the data
    [dists,inds] = sort(dists); slps = slps(inds);

    %Next go through the neurons and get average distance and response measures
    num1 = ceil(length(slps)/nGroups); num2 = mod(length(slps), nGroups);
    groups = ones(1,nGroups).*num1; 
    if num2 ~= 0; groups(1:(nGroups-num2)) = groups(1:(nGroups-num2)) - 1; end

    clearvars gSlps gError gDists
    start = 0; stop = 0;
    for i = 1:nGroups
        start = stop + 1; stop = stop + groups(i);
        gSlps(i) = mean(slps(start:stop)); gDists(i) = mean(dists(start:stop)); 
        gError(i) = std(slps(start:stop))/sqrt((stop - start));
    end

    
    if k == 1
        figure(1)
        shadedErrorBar(gDists,gSlps,gError,'lineProps',{'LineStyle','--','Color','k'})
        hold on
        
        figure(2)
        shadedErrorBar(gDists,gSlps,gError,'lineProps',{'LineStyle','--','Color','k'})
        hold on
        plot(gDists,gSlps,'LineWidth',1.5,'LineStyle','--','Color','k');
        
    else
        figure(k-1)
        shadedErrorBar(gDists,gSlps,gError,'lineProps',{'Color','r'})
        hold on
        plot(gDists,gSlps,'LineWidth',1.5,'Color','r');
    end
    ylim([0 3])
    box off
    xlabel('Distance to SVM Line (microns)')
    ylabel('Slope Re:Baseline')
    count = count + 1;
end

figure(1)
title('Compared to Days 0-2')

figure(2)
title('Compared to Day 7')

%%
%Next create the slope summary - Figure 5C.


